package cn.ztuo.bitrade.controller;

import cn.ztuo.bitrade.entity.ContractBond;
import cn.ztuo.bitrade.entity.transform.AuthMember;
import cn.ztuo.bitrade.service.ContractBondService;
import cn.ztuo.bitrade.service.ContractCoinService;
import cn.ztuo.bitrade.util.ContractUtils;
import cn.ztuo.bitrade.util.MessageResult;
import cn.ztuo.bitrade.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static cn.ztuo.bitrade.constant.SysConstant.SESSION_MEMBER;

/**
 * @author 焦河河
 */

@RestController
@RequestMapping(value = "/location_value")
public class LocationValueController {
    @Autowired
    private ContractCoinService contractCoinService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ContractBondService bondService;

    /**
     * 实时获取 杠杆 动态;
     * @param symbol 交易对
     * @param nowp 数量
     * @return
     */
    @PostMapping(value = "/calculation")
    public MessageResult calculation(@SessionAttribute(SESSION_MEMBER) AuthMember authMember,String symbol, BigDecimal nowp) {
        List<ContractBond> bonds = new ArrayList<>();
        MessageResult messageResult = new MessageResult();
        if(symbol==null){
            messageResult.setData(bonds);
            return messageResult;
        }
        if(nowp==null){
            nowp=BigDecimal.ZERO;
        }
        bonds = ContractUtils.getTimelyBonds(authMember.getId(),symbol,nowp);
        if(bonds==null||bonds.size()<=0){
            messageResult.setMessage("交易数量超过最大限制");
            messageResult.setCode(-1);
        }else{
            messageResult.setData(bonds);
        }
        return messageResult;
    }
}
